<?php
/**
 * Flea Site
 *
 * @copyright  Copyright (c) 2008 Movoin Studio (http://movoin.com)
 * @license    Apache License 2.0
 * @version    $Id: Guestbook.php 138 2009-05-25 06:42:38Z movoin $
 */

//{{include
FLEA::loadClass('Controller_Base');
//}}

class Controller_Guestbook extends Controller_Base
{

    var $modelGuestbook;

    function Controller_Guestbook()
    {
        parent::Controller_Base();
        $this->modelGuestbook =& FLEA::getSingleton( 'Model_Guestbook' );
    }

    function actionIndex()
    {
        $this->_setBack();
        $data['focus'] = 'column';
        $data['column'] = $this->getColumnInf( $_GET[FLEA::getAppInf( 'columnAccessor' )] );

        $table =& $this->modelGuestbook->getTable();
        $where = array(
            array( 'col_key', $_GET[FLEA::getAppInf( 'columnAccessor' )] ),
            array( 'site_id', (int)$_GET['site'] )
            );
        FLEA::loadHelper( 'pager' );
        $page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
        $pagesize = 6;
        $pager =& new FLEA_Helper_Pager($table, $page, $pagesize, $where, 'created DESC');
        $data['rows'] = $pager->findAll('comment_id,options,displayorder,content,created');
        $data['pager'] = $pager->getPagerData();
        FLEA::loadFile( 'Helper_Common' );
        $this->_executeView('guestbook', $data);
    }

    function actionReply()
    {
        $data['focus'] = 'column';
        $comment = (int)$_GET['commentid'];
        $data['row'] = $this->modelGuestbook->getMessage($comment);
        FLEA::loadFile( 'Helper_Common' );
        $this->_executeView('guestbook-reply', $data);
    }

    function actionSave()
    {
        js_alert($this->modelGuestbook->replyMessage(&$_POST), 0, $this->_getBack());
    }

    function actionRemove()
    {
        js_alert($this->modelGuestbook->removeMessage($_GET['commentid']), 0, $this->_getBack());
    }

    function actionVisibility()
    {
        $comment = (int)$_GET['commentid'];
        $displayorder = (int)$_GET['display']==0?1:0;
        js_alert($this->modelGuestbook->visibility($comment, $displayorder), 0, $this->_getBack());
    }

}
